import random

from readyaml import ReadYamlData


class DebugTalk:
    def __init__(self):
        self.read = ReadYamlData()

    def get_extract_order_data(self, data, randoms):
        if randoms not in [0, -1, -2]:
            return data[randoms-1]

    def get_extract_data(self, node_name, randoms=None):
        """
        获取 extract.yaml中的 数据
        :param node_name: extract.yaml 中的 key值
        :param randoms: 随机读取 extract.yaml 中的数据
        :return:
        """
        data = self.read.get_extract_yaml(node_name)
        # print("data:---------------------", data)
        # TODO 处理列表类型的数据
        if randoms is not None:
            irandoms = int(randoms)
            # TODO 0：随机读取一个数据
            # TODO -1：读取全部的数据
            data_value = {
                irandoms: self.get_extract_order_data(data, irandoms),
                0: random.choice(data),
                -1: ','.join(data),
                -2: ','.join(data).split(',')
            }
            data = data_value[irandoms]
        return data

    def md5_params(self, params):
        print('实现md5加密')
        return 'ABCD---' + str(params)


if __name__ == '__main__':
    debug = DebugTalk()
    # Token = debug.get_extract_data('Token')
    # # Product_ID = debug.get_extract_data('product_id')
    # # print(Token)
    # # print(Product_ID)
    #
    # Product_ID_0 = debug.get_extract_data('product_id', 0)
    # print(Product_ID_0)
    #
    # Product_ID_ALL = debug.get_extract_data('product_id', -1)
    # print(Product_ID_ALL)
    #
    # Product_ID_2 = debug.get_extract_data('product_id', -2)
    # print(Product_ID_2)

    Product_ID_SURE = debug.get_extract_data('product_id', 2)
    print(Product_ID_SURE)

